package me.zk.practice1.s;

/**
 * @Author: zhang kai
 * @Date: 2023/04/26
 * @Description:
 */
public class S1 {
    static int[] array = {1,2,3,4,5,6,7,8,9};
    static int b = 6;
    public static void main(String[] args) {
        int index =0;
        int left = 1;
        int right = array.length ;
        int i =0;
        while (true) {
            i++;
            index = (left+right)/2;
            if (array[index] == b) {
                System.out.println("位置："+ index);
                break;
            } else if (array[index]>b){
                right = index;
            } else {
                left = index;
            }

            if (index == array.length-1) {
                break;
            }
        }
        System.out.println("遍历次数："+ i);
    }
}
